<template>
  <div class="app-container box">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card shadow="hover" :body-style="{height:'148px',padding:'0'}">
          <div style="height: 100%;">
            <div class="head-chart">
                <span class="icon-chart">
                   动态标题
                </span>
            </div>
            <div class="chart-pic flex">
              <el-button size="medium"  type="primary" @click="changeTitle(0)">标题变更为 河北彩花</el-button>
              <el-button size="medium"  type="primary" @click="changeTitle(1)">还原为默认标题</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" :body-style="{height:'148px',padding:'0'}">
          <div style="height: 100%;">
            <div class="head-chart">
                <span class="icon-chart">
                   动态图标
                </span>
            </div>
            <div class="chart-pic flex">
              <el-popover
                placement="top-start"
                width="292"
                trigger="hover">
                <el-button slot="reference">
                  <i :class="firstIcon" class="first-icon"></i>更多菜单<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-row :gutter="20" >
                  <el-col :span="24">
                    <div class="top-panel">
                      <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <el-form-item >
                          <el-input v-model="formInline.iconName"></el-input>
                        </el-form-item>
                        <el-form-item>
                          <el-button type="primary" @click="onSubmit">查询</el-button>
                        </el-form-item>
                      </el-form>
                    </div>
                  </el-col>
                </el-row>
                <el-row class="icon-box" :gutter="20">
                  <el-col :span="6"
                          style="margin-bottom: 20px"
                          @click.native="getIcon(item.name)"
                          v-for="(item,index) in iconList.slice((pages.pageNum-1)*pages.pageSize,pages.pageNum*pages.pageSize)" :key="index">
                    <el-card shadow="hover" :body-style="{ padding:'20px',height: '20px',width:'50px'}">
                      <i :class="item.name" id="icon"></i>
                    </el-card>
                  </el-col>
                </el-row>
                <el-row >
                  <el-col :span="24">
                    <Pagination
                      :total="iconList.length" :pageNum.sync="pages.pageNum"
                      :limit.sync="pages.pageSize"
                      :layout="`total, prev, next`"
                    ></Pagination>
                  </el-col>
                </el-row>
              </el-popover>
            </div>

          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" :body-style="{height:'148px',padding:'0'}">
          <div style="height: 100%;">
            <div class="head-chart">
                <span class="icon-chart">
                   动态徽章
                </span>
            </div>
            <div class="chart-pic flex">
              <el-button size="medium"  type="primary" @click="changeIcon('add')">徽章+1</el-button>
              <el-button size="medium"  type="primary" @click="changeIcon('0')">徽章清零</el-button>
              <el-button size="medium"  type="primary" @click="changeIcon('remove')">移除徽章</el-button>
            </div>
          </div>
        </el-card>
      </el-col>

    </el-row>

  </div>
</template>

<script>
import { iconList } from '@/utils/icon'
import Pagination from '@/components/Pagination/Pagination'
export default {
  name: 'dynamicMeta',
  components:{Pagination},
  data(){
      return {
        title:'',
        iconList: iconList,
        dataList:iconList,
        formInline: {
          iconName: ''
        },
        pages: {
          pageNum: 1,
          pageSize: 16
        },
        firstIcon:''
  }
  },
  methods:{
    getIcon(name){
      this.firstIcon = name
      this.$route.meta.icon = name
      this.$EventBus.$emit('changeIcon',name)
    },
    onSubmit() {
      let list = []
      this.iconList = this.dataList
      for (let i = 0; i < this.iconList.length; i++) {
        if (this.iconList[i].name.indexOf(this.formInline.iconName)>= 0){
          list.push(this.iconList[i])
        }
      }
      this.iconList = list
    },
    changeIcon(params){
      if (params==='0'){
        this.$EventBus.$emit('toBadge')
      }else if (params==='add'){
        this.$EventBus.$emit('addBadge')
      }else {
        this.$EventBus.$emit('removeBadge')
      }
    },
    changeTitle(params){
      this.$EventBus.$emit('changeIcon')
      if (params===0){
        document.title = '河北彩花'
        this.$route.meta.title = '河北彩花'
      }else {
        document.title = this.title
        this.$route.meta.title= this.title
      }
    }
  },
  mounted() {
    this.firstIcon = iconList[0].name
    this.title = this.$route.meta.title
  }

}
</script>

<style scoped lang="scss">
.first-icon {
  font-size: 14px;
  vertical-align: -2px;
  margin-right: 2px;
}
.el-popover{
  .top-panel {
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    align-items: center;
    justify-content: flex-start;
    min-height: 32px;
    margin: 0 0 10px 0;

  }

}
.icon-box{
  .el-col{
    margin-bottom: 20px;
  }
  .el-card{
    width: 52px;
    height: 42px;
    text-align: center;

  }
  ::v-deep.el-card .el-card__body{
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 20px;
    cursor: pointer;
    i{
      font-size: 28px;
      color: gray;
      text-align: center;
      vertical-align: middle;
      pointer-events: none;
      cursor: pointer;
    }
  }
}
::v-deep.el-row {
  margin-bottom: 0;
  &:last-child {
    margin-bottom: 0;
  }
}
.box{

  .head-chart {
    display: flex;
    padding: 20px 20px 20px 20px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #E4E7ED;

    .icon-chart {
      font-size: 14px;

      i {
        margin-right: 5px;
      }
    }
  }
  .chart-pic{
    margin-top: 30px;
  }
}
</style>
